package com.applet.setmeal.controller;


import com.applet.entity.Setmeal;
import com.applet.result.Result;
import com.applet.setmeal.service.SetMealService;
import com.applet.vo.DishItemVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 套餐管理 controller
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/user/setmeal")
public class SetMealController {

    @Resource
    private SetMealService setMealService;



    /**
     * 套餐管理
     *        根据分类id 查询套餐集合
     * @param categoryId
     */
    @GetMapping("/list")
    public Result<List<Setmeal>> selectSetMealListByCategoryId(@NotNull(message = "分类id为空") Long categoryId){
        log.info("套餐管理 - 根据分类id: {} 查询套餐集合", categoryId);
        List<Setmeal> setmealList = setMealService.selectSetMealListByCategoryId(categoryId);
        return Result.success(setmealList);
    }



    /**
     * 套餐管理
     *        根据套餐id 查询套餐关联的菜品集合
     * @param id
     */
    @GetMapping("/dish/{id}")
    public Result<List<DishItemVO>> dishInSetMeal(@PathVariable(name="id") Long id){
        log.info("套餐管理 - 根据套餐id: {} 查询套餐关联的菜品集合", id);
        List<DishItemVO> dishItemVOList = setMealService.dishInSetMeal(id);
        return Result.success(dishItemVOList);

    }

}
